//
//  CURLDataLoader.h
//  IOSLIB
//
//  Created by 张靖 on 10-10-14.
//  Copyright 2010 MyQuan. Inc.. All rights reserved.
//

#import <Foundation/Foundation.h>

enum
{
	eURLErrorNone,
	eURLErrorNotConnectedToInternet,
	eURLErrorCannotConnectToHost,
	eURLErrorReceiveDataZeroLength,
	eURLErrorTimeout,
	eURLErrorUnknown
};
typedef int TUrlDataLoadErrorCode;

@class CURLDataLoader;
@protocol CURLDataLoaderDelegate<NSObject>

@optional
- (void) urlDataLoadRecvHeader:(CURLDataLoader*)loader header:(NSDictionary*)header;
- (void) urlDataLoadProgress:(CURLDataLoader*)loader progress:(float)progress;
- (void) urlDataLoadCompleteInNewThread:(CURLDataLoader*)loader;
- (void) urlDataLoadComplete:(CURLDataLoader*)loader;
- (void) urlDataLoadError:(CURLDataLoader*)loader errorCode:(TUrlDataLoadErrorCode)errorCode;

@end

@interface CURLDataLoader : NSObject
{
	NSString* _urlStr;
	NSURLConnection* _urlConnection;
	NSMutableData* _urlData;
	
	float _contentLength;
	NSString *_httpMethod;

	id<CURLDataLoaderDelegate> _delegate;
}

@property (copy) NSString* urlStr;
@property (retain) NSMutableData* urlData;
@property (retain) NSURLConnection* urlConnection;
@property (assign) id<CURLDataLoaderDelegate> delegate;

+ (CURLDataLoader*) urlDataLoader;

- (void) loadMultiDataStart:(NSString*)url postData:(NSDictionary *)data header:(NSDictionary *)headerfield;
- (void) loadDataStart:(NSString*)url postData:(NSData *)data;
- (void) loadDataStart:(NSString*)url postData:(NSData *)data header:(NSDictionary *)headerfield;
- (void) loadDataStart:(NSString*)url header:(NSDictionary *)headerfield;
- (void) loadDataStart:(NSString*)url;
- (void) loadDataStartKeepAlive:(NSString*)url postData:(NSData *)data;

- (void) cancelLoadData;
- (BOOL) isLoading;

@end
